﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace PDFSignature.Models
{

    /// <summary>
    /// 签章视图
    /// </summary>
    public class SignatureView
    {
        /// <summary>
        /// 只读模式
        /// </summary>
        public bool OnlyRead { set; get; }

        /// <summary>
        /// 文件路径(远程)
        /// </summary>
        public string PdfUrl { set; get; }



        /// <summary>
        /// 文件路径(服务端本地)
        /// </summary>
        public string PdfPath { set; get; }


        /// <summary>
        /// 合同名称
        /// </summary>
        public string ContractName { set; get; }

        /// <summary>
        /// 合同编号
        /// </summary>
        public string ContractId { set; get; }


        /// <summary>
        /// 签章信息
        /// </summary>
        public List<Signature> Signatures { set; get; }
        /// <summary>
        /// 合同方信息
        /// </summary>
        public List<ContractPartysInfo> ContractPartysInfos { set; get; }


        /// <summary>
        /// 每页行信息
        /// </summary>
        public List<PageInfo>  PageInfos { set; get; }



        /// <summary>
        ///  以页码分组的签章信息
        /// </summary>
        public Dictionary<string,List<Signature>> SignaturesPageView
        { 
            get {
                Dictionary<string, List<Signature>> view = new Dictionary<string, List<Signature>>();
                if (Signatures != null)
                {
                    foreach (var item in Signatures)
                    {
                        string key = item.PageIndex.ToString();
                        if (view.ContainsKey(key))
                        {
                            view[key].Add(item);
                        }
                        else
                        {
                            view[key] = new List<Signature>()
                        {
                            item
                        };
                        }
                    }
                }
          
                return view;
            }
        }

        /// <summary>
        ///  以合同方分组的签章信息
        /// </summary>
        public Dictionary<string, List<Signature>> SignaturesPartysView
        {
            get
            {
                Dictionary<string, List<Signature>> view = new Dictionary<string, List<Signature>>();
                if (Signatures != null)
                {
                    foreach (var item in Signatures)
                    {
                        string key = item.ContractPartys.ToString();

                        if (view.ContainsKey(key))
                        {
                            view[key].Add(item);
                        }
                        else
                        {
                            view[key] = new List<Signature>()
                        {
                            item
                        };
                        }
                    }
                }
             
                return view;
            }
        }

    }

    public class PageInfo
    {
        public float Height { set; get; }
        public float Width { set; get; }

        public int PageIndex { set; get; }
    }

    public class ContractPartysInfo {
        /// <summary>
        /// 签章顺序
        /// </summary>
        public int Sequence { set; get; }

        /// <summary>
        /// 合同方 01234甲乙丙丁
        /// </summary>
        public string ContractPartys { set; get; }

        /// <summary>
        /// 主体名
        /// </summary>
        public string VendorName { set; get; }

        /// <summary>
        /// 签约类型
        /// </summary>
        public string SignatureType { set; get; }

        /// <summary>
        /// 签字人
        /// </summary>
        public string PartyPrimeSignature { set; get; }
    }

    public class Signature
    {
        /// <summary>
        /// 合同方 01234 甲乙丙丁...
        /// </summary>
        public string ContractPartys { set; get; }

        /// <summary>
        /// 签章方式  关键字定位  坐标定位
        /// </summary>
        public TakeAimMode SignMode { set; get; }

        /// <summary>
        /// 关键字
        /// </summary>
        public string KeyWord { set; get; }
        /// <summary>
        /// 签署位置X坐标,若为关键字定位，相对于关键字的X坐标偏移量，默认0
        /// </summary>
        public float PosX { get; set; }

        /// <summary>
        /// 签署位置Y坐标,若为关键字定位，相对于关键字的Y坐标偏移量，默认0
        /// </summary>
        public float PosY { get; set; }

        /// <summary>
        /// 所在页码
        /// </summary>
        public int PageIndex { set; get; }


        /// <summary>
        /// 章类型
        /// 1/ 负责人签字
        /// 2/ 公章
        /// 3  代办人签字
        /// 11/ 时间戳
        /// </summary>
        public SealTypeEnum SealType { set; get; }
    }



    /// <summary>
    /// 签章定位方式
    /// </summary>
    public enum TakeAimMode
    {
        /// <summary>
        /// 关键字
        /// </summary>
        keyWord,

        /// <summary>
        /// 坐标
        /// </summary>
        Coordinate
    }

    public enum SealTypeEnum {

        /// <summary>
        /// 负责人签字
        /// </summary>
        PersonalSeal = 1 ,

        /// <summary>
        /// 主体公章
        /// </summary>
        CorporateSeal = 2 ,

        /// <summary>
        /// 盖章人签字
        /// </summary>
        ProxySeal = 3,

        /// <summary>
        /// 时间戳
        /// </summary>
        TimeStamp = 11,

    }

}
